package cn.jkm.provider.content.v1_0.content;

import cn.jkm.core.domain.mongo.content.UserFollows;
import cn.jkm.core.domain.type.Status;
import cn.jkm.framework.mongo.mongo.Mongo;
import cn.jkm.service.content.FollowService;

/**
 * @author zhong
 * @version V1.0
 * @project jkm-root
 * @package cn.jkm.provider.content.v1_0.content
 * @description //关注服务的实现
 * @update 2017/7/27 17:07
 */
public class FollowServiceImpl implements FollowService{
    @Override
    public void follow(String userId, String followedUserId) {
        UserFollows userFollows = Mongo.buildMongo()
                .eq("followUserId",userId)
                .eq("followedUserId",followedUserId)
                .findOne(UserFollows.class);
        if(userFollows==null){
            userFollows = new UserFollows();
            userFollows.setStatus(Status.ACTIVE);
            userFollows.setFollowUserId(userId);
            userFollows.setFollowedUserId(followedUserId);
            Mongo.buildMongo().insert(userFollows);
        }
    }

    @Override
    public void unFollow(String userId, String followedUserId) {
        Mongo.buildMongo().eq("followUserId",userId)
                .eq("followedUserId",followedUserId)
                .remove("user_follows");
    }
}
